home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / mallcrawl.swf / scripts / __Packages / mx / core / ScrollView.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  11.0 KB  |  377 lines

  1. class mx.core.ScrollView extends mx.core.View
  2. {
  3.    var __width;
  4.    var hScroller;
  5.    var vScroller;
  6.    var __maxHPosition;
  7.    var propsInited;
  8.    var scrollAreaChanged;
  9.    var specialHScrollCase;
  10.    var viewableColumns;
  11.    var __height;
  12.    var viewableRows;
  13.    var oldRndUp;
  14.    var __viewMetrics;
  15.    var owner;
  16.    var border_mc;
  17.    var invLayout;
  18.    var mask_mc;
  19.    var dispatchEvent;
  20.    static var symbolName = "ScrollView";
  21.    static var symbolOwner = mx.core.ScrollView;
  22.    static var version = "2.0.2.126";
  23.    var className = "ScrollView";
  24.    var __vScrollPolicy = "auto";
  25.    var __hScrollPolicy = "off";
  26.    var __vPosition = 0;
  27.    var __hPosition = 0;
  28.    var numberOfCols = 0;
  29.    var rowC = 0;
  30.    var columnWidth = 1;
  31.    var rowH = 0;
  32.    var heightPadding = 0;
  33.    var widthPadding = 0;
  34.    var MASK_DEPTH = 10000;
  35.    function ScrollView()
  36.    {
  37.       super();
  38.    }
  39.    function getHScrollPolicy(Void)
  40.    {
  41.       return this.__hScrollPolicy;
  42.    }
  43.    function setHScrollPolicy(policy)
  44.    {
  45.       this.__hScrollPolicy = policy.toLowerCase();
  46.       if(this.__width == undefined)
  47.       {
  48.          return undefined;
  49.       }
  50.       this.setScrollProperties(this.numberOfCols,this.columnWidth,this.rowC,this.rowH,this.heightPadding,this.widthPadding);
  51.    }
  52.    function get hScrollPolicy()
  53.    {
  54.       return this.getHScrollPolicy();
  55.    }
  56.    function set hScrollPolicy(policy)
  57.    {
  58.       this.setHScrollPolicy(policy);
  59.    }
  60.    function getVScrollPolicy(Void)
  61.    {
  62.       return this.__vScrollPolicy;
  63.    }
  64.    function setVScrollPolicy(policy)
  65.    {
  66.       this.__vScrollPolicy = policy.toLowerCase();
  67.       if(this.__width == undefined)
  68.       {
  69.          return undefined;
  70.       }
  71.       this.setScrollProperties(this.numberOfCols,this.columnWidth,this.rowC,this.rowH,this.heightPadding,this.widthPadding);
  72.    }
  73.    function get vScrollPolicy()
  74.    {
  75.       return this.getVScrollPolicy();
  76.    }
  77.    function set vScrollPolicy(policy)
  78.    {
  79.       this.setVScrollPolicy(policy);
  80.    }
  81.    function get hPosition()
  82.    {
  83.       return this.getHPosition();
  84.    }
  85.    function set hPosition(pos)
  86.    {
  87.       this.setHPosition(pos);
  88.    }
  89.    function getHPosition(Void)
  90.    {
  91.       return this.__hPosition;
  92.    }
  93.    function setHPosition(pos)
  94.    {
  95.       this.hScroller.scrollPosition = pos;
  96.       this.__hPosition = pos;
  97.    }
  98.    function get vPosition()
  99.    {
  100.       return this.getVPosition();
  101.    }
  102.    function set vPosition(pos)
  103.    {
  104.       this.setVPosition(pos);
  105.    }
  106.    function getVPosition(Void)
  107.    {
  108.       return this.__vPosition;
  109.    }
  110.    function setVPosition(pos)
  111.    {
  112.       this.vScroller.scrollPosition = pos;
  113.       this.__vPosition = pos;
  114.    }
  115.    function get maxVPosition()
  116.    {
  117.       var _loc2_ = this.vScroller.maxPos;
  118.       return _loc2_ != undefined ? _loc2_ : 0;
  119.    }
  120.    function get maxHPosition()
  121.    {
  122.       return this.getMaxHPosition();
  123.    }
  124.    function set maxHPosition(pos)
  125.    {
  126.       this.setMaxHPosition(pos);
  127.    }
  128.    function getMaxHPosition(Void)
  129.    {
  130.       if(this.__maxHPosition != undefined)
  131.       {
  132.          return this.__maxHPosition;
  133.       }
  134.       var _loc2_ = this.hScroller.maxPos;
  135.       return _loc2_ != undefined ? _loc2_ : 0;
  136.    }
  137.    function setMaxHPosition(pos)
  138.    {
  139.       this.__maxHPosition = pos;
  140.    }
  141.    function setScrollProperties(colCount, colWidth, rwCount, rwHeight, hPadding, wPadding)
  142.    {
  143.       var _loc3_ = this.getViewMetrics();
  144.       if(hPadding == undefined)
  145.       {
  146.          hPadding = 0;
  147.       }
  148.       if(wPadding == undefined)
  149.       {
  150.          wPadding = 0;
  151.       }
  152.       this.propsInited = true;
  153.       delete this.scrollAreaChanged;
  154.       this.heightPadding = hPadding;
  155.       this.widthPadding = wPadding;
  156.       if(colWidth == 0)
  157.       {
  158.          colWidth = 1;
  159.       }
  160.       if(rwHeight == 0)
  161.       {
  162.          rwHeight = 1;
  163.       }
  164.       var _loc5_ = Math.ceil((this.__width - _loc3_.left - _loc3_.right - this.widthPadding) / colWidth);
  165.       if(this.__hScrollPolicy == "on" || _loc5_ < colCount && this.__hScrollPolicy == "auto")
  166.       {
  167.          if(this.hScroller == undefined || this.specialHScrollCase)
  168.          {
  169.             delete this.specialHScrollCase;
  170.             this.hScroller = this.createObject("HScrollBar","hSB",1001);
  171.             this.hScroller.lineScrollSize = 20;
  172.             this.hScroller.scrollHandler = this.scrollProxy;
  173.             this.hScroller.scrollPosition = this.__hPosition;
  174.             this.scrollAreaChanged = true;
  175.          }
  176.          if(this.numberOfCols != colCount || this.columnWidth != colWidth || this.viewableColumns != _loc5_ || this.scrollAreaChanged)
  177.          {
  178.             this.hScroller.setScrollProperties(_loc5_,0,colCount - _loc5_);
  179.             this.viewableColumns = _loc5_;
  180.             this.numberOfCols = colCount;
  181.             this.columnWidth = colWidth;
  182.          }
  183.       }
  184.       else if((this.__hScrollPolicy == "auto" || this.__hScrollPolicy == "off") && this.hScroller != undefined)
  185.       {
  186.          this.hScroller.removeMovieClip();
  187.          delete this.hScroller;
  188.          this.scrollAreaChanged = true;
  189.       }
  190.       if(this.heightPadding == undefined)
  191.       {
  192.          this.heightPadding = 0;
  193.       }
  194.       var _loc4_ = Math.ceil((this.__height - _loc3_.top - _loc3_.bottom - this.heightPadding) / rwHeight);
  195.       var _loc8_ = (this.__height - _loc3_.top - _loc3_.bottom) % rwHeight != 0;
  196.       if(this.__vScrollPolicy == "on" || _loc4_ < rwCount + _loc8_ && this.__vScrollPolicy == "auto")
  197.       {
  198.          if(this.vScroller == undefined)
  199.          {
  200.             this.vScroller = this.createObject("VScrollBar","vSB",1002);
  201.             this.vScroller.scrollHandler = this.scrollProxy;
  202.             this.vScroller.scrollPosition = this.__vPosition;
  203.             this.scrollAreaChanged = true;
  204.             this.rowH = 0;
  205.          }
  206.          if(this.rowC != rwCount || this.rowH != rwHeight || this.viewableRows + _loc8_ != _loc4_ + this.oldRndUp || this.scrollAreaChanged)
  207.          {
  208.             this.vScroller.setScrollProperties(_loc4_,0,rwCount - _loc4_ + _loc8_);
  209.             this.viewableRows = _loc4_;
  210.             this.rowC = rwCount;
  211.             this.rowH = rwHeight;
  212.             this.oldRndUp = _loc8_;
  213.          }
  214.       }
  215.       else if((this.__vScrollPolicy == "auto" || this.__vScrollPolicy == "off") && this.vScroller != undefined)
  216.       {
  217.          this.vScroller.removeMovieClip();
  218.          delete this.vScroller;
  219.          this.scrollAreaChanged = true;
  220.       }
  221.       this.numberOfCols = colCount;
  222.       this.columnWidth = colWidth;
  223.       if(this.scrollAreaChanged)
  224.       {
  225.          this.doLayout();
  226.          var _loc2_ = this.__viewMetrics;
  227.          var _loc12_ = this.owner == undefined ? this : this.owner;
  228.          _loc12_.layoutContent(_loc2_.left,_loc2_.top,this.columnWidth * this.numberOfCols - _loc2_.left - _loc2_.right,this.rowC * this.rowH,this.__width - _loc2_.left - _loc2_.right,this.__height - _loc2_.top - _loc2_.bottom);
  229.       }
  230.       if(!this.enabled)
  231.       {
  232.          this.setEnabled(false);
  233.       }
  234.    }
  235.    function getViewMetrics(Void)
  236.    {
  237.       var _loc2_ = this.__viewMetrics;
  238.       var _loc3_ = this.border_mc.borderMetrics;
  239.       _loc2_.left = _loc3_.left;
  240.       _loc2_.right = _loc3_.right;
  241.       if(this.vScroller != undefined)
  242.       {
  243.          _loc2_.right += this.vScroller.minWidth;
  244.       }
  245.       _loc2_.top = _loc3_.top;
  246.       if(this.hScroller == undefined && (this.__hScrollPolicy == "on" || this.__hScrollPolicy == true))
  247.       {
  248.          this.hScroller = this.createObject("FHScrollBar","hSB",1001);
  249.          this.specialHScrollCase = true;
  250.       }
  251.       _loc2_.bottom = _loc3_.bottom;
  252.       if(this.hScroller != undefined)
  253.       {
  254.          _loc2_.bottom += this.hScroller.minHeight;
  255.       }
  256.       return _loc2_;
  257.    }
  258.    function doLayout(Void)
  259.    {
  260.       var _loc10_ = this.width;
  261.       var _loc8_ = this.height;
  262.       delete this.invLayout;
  263.       var _loc0_ = null;
  264.       var _loc3_ = this.__viewMetrics = this.getViewMetrics();
  265.       var _loc2_ = _loc3_.left;
  266.       var _loc9_ = _loc3_.right;
  267.       var _loc5_ = _loc3_.top;
  268.       var _loc11_ = _loc3_.bottom;
  269.       var _loc7_ = this.hScroller;
  270.       var _loc6_ = this.vScroller;
  271.       _loc7_.setSize(_loc10_ - _loc2_ - _loc9_,_loc7_.minHeight + 0);
  272.       _loc7_.move(_loc2_,_loc8_ - _loc11_);
  273.       _loc6_.setSize(_loc6_.minWidth + 0,_loc8_ - _loc5_ - _loc11_);
  274.       _loc6_.move(_loc10_ - _loc9_,_loc5_);
  275.       var _loc4_ = this.mask_mc;
  276.       _loc4_._width = _loc10_ - _loc2_ - _loc9_;
  277.       _loc4_._height = _loc8_ - _loc5_ - _loc11_;
  278.       _loc4_._x = _loc2_;
  279.       _loc4_._y = _loc5_;
  280.    }
  281.    function createChild(id, name, props)
  282.    {
  283.       var _loc2_ = super.createChild(id,name,props);
  284.       return _loc2_;
  285.    }
  286.    function init(Void)
  287.    {
  288.       super.init();
  289.       this.__viewMetrics = new Object();
  290.       if(_global.__SVMouseWheelManager == undefined)
  291.       {
  292.          var _loc0_ = null;
  293.          var _loc4_ = _global.__SVMouseWheelManager = new Object();
  294.          _loc4_.onMouseWheel = this.__onMouseWheel;
  295.          Mouse.addListener(_loc4_);
  296.       }
  297.    }
  298.    function __onMouseWheel(delta, scrollTarget)
  299.    {
  300.       var _loc4_ = scrollTarget;
  301.       var _loc1_ = undefined;
  302.       while(_loc4_ != undefined)
  303.       {
  304.          if(_loc4_ instanceof mx.core.ScrollView)
  305.          {
  306.             _loc1_ = _loc4_;
  307.             false;
  308.          }
  309.          _loc4_ = _loc4_._parent;
  310.       }
  311.       if(_loc1_ != undefined)
  312.       {
  313.          _loc4_ = delta > 0 ? -1 : 1;
  314.          var _loc2_ = _loc1_.vScroller.lineScrollSize;
  315.          if(_loc2_ == undefined)
  316.          {
  317.             _loc2_ = 0;
  318.          }
  319.          _loc2_ = Math.max(Math.abs(delta),_loc2_);
  320.          var _loc3_ = _loc1_.vPosition + _loc2_ * _loc4_;
  321.          _loc1_.vPosition = Math.max(0,Math.min(_loc3_,_loc1_.maxVPosition));
  322.          _loc1_.dispatchEvent({type:"scroll",direction:"vertical",position:_loc1_.vPosition});
  323.       }
  324.    }
  325.    function createChildren(Void)
  326.    {
  327.       super.createChildren();
  328.       if(this.mask_mc == undefined)
  329.       {
  330.          this.mask_mc = this.createObject("BoundingBox","mask_mc",this.MASK_DEPTH);
  331.       }
  332.       this.mask_mc._visible = false;
  333.    }
  334.    function invalidate(Void)
  335.    {
  336.       super.invalidate();
  337.    }
  338.    function draw(Void)
  339.    {
  340.       this.size();
  341.    }
  342.    function size(Void)
  343.    {
  344.       super.size();
  345.    }
  346.    function scrollProxy(docObj)
  347.    {
  348.       this._parent.onScroll(docObj);
  349.    }
  350.    function onScroll(docObj)
  351.    {
  352.       var _loc3_ = docObj.target;
  353.       var _loc2_ = _loc3_.scrollPosition;
  354.       if(_loc3_ == this.vScroller)
  355.       {
  356.          var _loc4_ = "vertical";
  357.          var _loc5_ = "__vPosition";
  358.       }
  359.       else
  360.       {
  361.          _loc4_ = "horizontal";
  362.          _loc5_ = "__hPosition";
  363.       }
  364.       this[_loc5_] = _loc2_;
  365.       this.dispatchEvent({type:"scroll",direction:_loc4_,position:_loc2_});
  366.    }
  367.    function setEnabled(v)
  368.    {
  369.       this.vScroller.enabled = this.hScroller.enabled = v;
  370.    }
  371.    function childLoaded(obj)
  372.    {
  373.       super.childLoaded(obj);
  374.       obj.setMask(this.mask_mc);
  375.    }
  376. }
  377.